//所有路由相关的代码都放在这个文件
const express=require('express')
// console.log(express)

const  router=express.Router();

router.get('/home',(req,res)=>{
     res.send({name:'home',age:100,sex:'男'})    
})

router.get('/news',(req,res)=>{
    res.send({name:'news',age:100,sex:'女'})
   
})


//  url= http://localhost:3000/books?id=xxxxx  获取get请求的动态参    req.query
router.get('/books',(req,res)=>{
    console.log(req.query)

    res.send({name:'books',age:100,sex:'女',...req.query})
   
})

//动态路由2     url= http://localhost:3000/users/000    获取get请求过来的参数 req.params
router.get('/users/:id',(req,res)=>{
    console.log(req.params)
    res.send({name:'users',...req.params})
})



//动态路由多个参数  
router.get('/users/:id/young/:names',(req,res)=>{
    console.log(req.params)
    res.send({name:'youngusers',...req.params})
})


// post 请求    获取动态参数  需要借用第三方插件 body-parser    数据在req.body身上
router.post('/post',(req,res)=>{
    console.log(req.body)
    res.send({name:'post',method:'post请求',...req.body})
})










//导出 
module.exports =router;








